﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM;
using System.Web.UI.HtmlControls; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class DC_InvestDisciplinePopup : System.Web.UI.UserControl
    {
          
        private string id;
        private object _dataItem = null;

        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }

        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);        
            lblInvSeq.Text = Session["inv_seq"].ToString() ;  
            
       
            if (!IsUserControlPostBack)
            {

                bindCombo();


                this.ViewState.Add("IsUserControlPostBack", true);
            }
            if (DataItem != null)
            {
                //   cbGender.ListGenderComboBox();
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
                    bindCombo();
                    string st = DataBinder.Eval(DataItem, "inv_emp_seq").ToString();
                    EmployeeInfo infoEmp;
                    IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
                    infoEmp = infoList[0];

                    lblEmpSeq.Text = infoEmp.Sequence.ToString();
                    lblPosName.Text = infoEmp.Position.Name != null ? infoEmp.Position.Name.ToString() : "";
                    lblClassName.Text = ""; // infoEmp.Position.ClassSpecification.Name != null ? infoEmp.Position.ClassSpecification.Name.ToString() : "";     
                    lblJobsiteName.Text = infoEmp.WorkingJobSite.Name != null ? infoEmp.WorkingJobSite.Name.ToString() : "";
                    lblPosRefNo.Text = infoEmp.Position.RefNo != null ? infoEmp.Position.RefNo.ToString() : "";
                    txtEmp.Text = infoEmp.Person.FirstName.ToString() + "   " + infoEmp.Person.LastName.ToString();
                    lblInvDtlsSeq.Text = DataBinder.Eval(DataItem, "inv_dtls_seq").ToString();
                    lblJobsiteName.Text  = DataBinder.Eval(DataItem, "job_site_name").ToString();
                    txtCrime.Text  = DataBinder.Eval(DataItem, "crd_descr").ToString();
                    txtDesc.Text = DataBinder.Eval(DataItem, "remarks").ToString();
                    ComboCrime.SelectedValue = DataBinder.Eval(DataItem, "crd_seq").ToString();

                    btnFindEmp.Visible = false;                
                    this.ViewState.Add("IsUserControlPostBack", true);
                }
                else
                {
                    //bindJobSite();
                    //rdoApr.SelectedValue = "0";
                    //rdoPromote.SelectedValue = "0";
                    //rdoApr_SelectedIndexChanged(null, null);
                }
                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }
        }


        public void IncludeJava()
        {
            HtmlGenericControl script = new HtmlGenericControl();
            script.TagName = "script";
            script.Attributes.Add("type", "text/javascript");
            script.Attributes.Add("src", "../../Scripts/jsfunction.js");
            Page.Header.Controls.Add(script);
        }



  

        protected void Page_Load(object sender, EventArgs e)
        {

              
              

        
        }
        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }

     
        protected void btnAddnew_Click(object sender, EventArgs e)
        {

            int inv_seq,inv_emp_seq,crd_seq;
            string crd_desc, remarks;

            inv_emp_seq = int.Parse(lblEmpSeq.Text);
            inv_seq = int.Parse(lblInvSeq.Text);
            crd_seq = int.Parse(ComboCrime.SelectedValue);

            crd_desc = txtCrime.Text;  
            remarks = txtDesc.Text;  
            InvestDesciplineBLL obj = new InvestDesciplineBLL();

            if (obj.chkDup(inv_seq,inv_emp_seq) != true)
            {
                obj.InsertDtls(inv_seq, inv_emp_seq, crd_seq, crd_desc, remarks, "1");
            }

        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {

            int inv_dtls_seq, inv_emp_seq, crd_seq;
            string crd_desc, remarks;

            inv_emp_seq = int.Parse(lblEmpSeq.Text);
            inv_dtls_seq = int.Parse(lblInvDtlsSeq.Text  );
            crd_seq = int.Parse(ComboCrime.SelectedValue);

            crd_desc = txtCrime.Text;  
            remarks = txtDesc.Text;


            InvestDesciplineBLL obj = new InvestDesciplineBLL();

            obj.UpdateDtls(inv_dtls_seq, inv_emp_seq, crd_seq, crd_desc, remarks, "1");     



        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }

        private IEmployeeBLL empBLL = new EmployeeBLL();
        protected void btnFindEmp_Click(object sender, ImageClickEventArgs e)
        {


            string st = Hide.Value;

            if (st == "")
                return;
       
            EmployeeInfo infoEmp;
            IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
            infoEmp = infoList[0];


           // infoEmp.Class.Sequence != null

            lblEmpSeq.Text = infoEmp.Sequence.ToString();
            lblPosName.Text = lblPosName.Text = infoEmp.Position.Name != null ? infoEmp.Position.Name.ToString() : "";  
            lblClassName.Text = infoEmp.Class.Name != null ? infoEmp.Class.Name.ToString() : "";
            lblJobsiteName.Text = infoEmp.WorkingJobSite.Name != null ? infoEmp.WorkingJobSite.Name.ToString() : "";
       
         
            lblPosRefNo.Text = infoEmp.Position.RefNo != null ? infoEmp.Position.RefNo.ToString(): "";
            txtEmp.Text = infoEmp.Person.FirstName.ToString() + "   " + infoEmp.Person.LastName.ToString();

      
          
               
        }


        private void bindCombo()
        {
            InvestDesciplineBLL obj = new InvestDesciplineBLL();

            DataTable dt;
            dt = obj.SelectComboCrime ();


            ComboCrime.DataValueField = "crd_seq";
            ComboCrime.DataTextField = "crd_name";
            ComboCrime.DataSource = dt;
            ComboCrime.DataBind(); 

        }





        protected void btnFindEmp_Load(object sender, EventArgs e)
        {
            if (DataItem is Telerik.Web.UI.GridInsertionObject)
            {

              
              
                string ETID = "0";
              
             //   btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogEmp.aspx?ETID=" + ETID + "&JSID=1','../frmIframe.html',700,500)");
             btnFindEmp.Attributes.Add("OnClick", "LinkMDdetail(" + Hide.ClientID + "," + "'Forms/DialogInvestDiscipline.aspx?ETID=" + ETID + "','../frmIframe.html',700,500)");
            }
        }

        protected void ComboCrime_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {




        }

     
    }
}